﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using BlogsAPI;
using VkontakteSharp;
using VkontakteSharp.Enums;
using VkontakteSharp.Model;

namespace VkontakteSharp.Endpoints.Users
{
    public class Authenticated : VkontakteAPI
    {
        public Authenticated(VkontakteConfig config, string authInfo) : base(config, authInfo, "/users.") { }

        /// <summary>
        /// Функция https://vk.com/dev/users.get, работающая с аутентификацией
        /// </summary>
        /// <param name="userIds">массив идентификаторов</param>
        /// <param name="fields">поля</param>
        /// <param name="name_case">падеж для возврата имен</param>
        /// <returns>Массив пользователей</returns>
        public Response<List<User>> GetById(string[] userIds, ProfileFields? fields = null, string name_case = null)
        {
            return (Response<List<User>>)Mapper.Map<Response<List<User>>>(GetByIdJson(userIds, fields, name_case));
        }

        public string GetByIdJson(string[] userIds, ProfileFields? fields = null, string name_case = null)
        {
            if (userIds.Length > 1000)
            {
                throw new ArgumentOutOfRangeException("userIds", "Can't be more than 1000");
            }
            string uri = string.Format(base.Uri + "get?v=3.0&access_token={0}&uids={1}", 
                AuthInfo,
                String.Join(",", userIds));
            if (fields.HasValue)
            {
                uri += "&fields=" + String.Join(",", fields.Value);
            }
            if (!String.IsNullOrEmpty(name_case))
            {
                uri += "&name_case=" + name_case;
            }
            return HttpClientOld.GET(uri);
        }


    }
}
